package com.hyc.myvideo.share;


import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.ShareContent;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.shareboard.ShareBoardConfig;

import timber.log.Timber;

/***
 * 分享工具类
 */
public class shareUtils {
    private Context mContext;
    public shareUtils(Context mContext,ShareContent content) {
        this.mContext = mContext;
        showShare(content);
    }

    /***
     * 分享面板设置
     * @return
     */
    private ShareBoardConfig getShareConfig(){
        ShareBoardConfig config = new ShareBoardConfig();
        //config.setShareboardPostion(ShareBoardConfig.SHAREBOARD_POSITION_CENTER);
        //config.setMenuItemBackgroundShape(ShareBoardConfig.BG_SHAPE_CIRCULAR); // 圆角背景
        config.setTitleVisibility(false); // 隐藏title
        config.setCancelButtonVisibility(false); // 隐藏取消按钮
        return config;
    }

    private void showShare(ShareContent content){
        new ShareAction((Activity)mContext).setShareContent(content)
                .setDisplayList(
                        SHARE_MEDIA.SINA,
                        SHARE_MEDIA.QQ,
                        SHARE_MEDIA.QZONE,
                        SHARE_MEDIA.WEIXIN,SHARE_MEDIA.WEIXIN_CIRCLE)
                .setCallback(umShareListener).open(getShareConfig());
    }





    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            //分享开始的回调
        }
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Timber.i("platform"+platform);
            Toast.makeText(mContext,platform + " 分享成功啦", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(mContext,platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
            if(t!=null){
                Timber.d("throw:"+t.getMessage());
            }
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(mContext,platform + " 分享取消了", Toast.LENGTH_SHORT).show();
        }
    };
}
